package com.crowd.service.impl;

import com.crowd.constant.CrowdConstant;
import com.crowd.mapper.MemberPOMapper;
import com.crowd.po.MemberPO;
import com.crowd.po.MemberPOExample;
import com.crowd.service.api.MysqlProviderService;
import com.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.List;

/**
 * @author Stone
 * @date 2020/6/23 17:22
 */
@Service
@Transactional(readOnly = true)
public class MySqlProviderServiceImpl implements MysqlProviderService {
    @Autowired
    private MemberPOMapper memberPOMapper;

    /**
     * @Author:Stone
       * @Param loginAcct:
       * @return: com.crowd.po.MemberPO
     * @Date: 2020/6/23 17:26
     * @Description: 通过loginAcct账号来查找member
    */
    public MemberPO getMemberPOByLoginAcct(String loginAcct) {
        MemberPOExample memberPOExample = new MemberPOExample();
        MemberPOExample.Criteria criteria = memberPOExample.createCriteria();
        criteria.andLoginacctEqualTo(loginAcct);
        List<MemberPO> memberPOS = memberPOMapper.selectByExample(memberPOExample);
        return memberPOS.get(0);
    }

    /**
     * @Author:Stone
       * @Param memberPO:
       * @return: com.crowd.po.MemberPO
     * @Date: 2020/6/30 15:52
     * @Description: 注册成功后，保存一个新的member对象
    */
    @Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class,readOnly = false)
    public void saveMemberPO(MemberPO memberPO) {
            // 插入数据，某字段没有数据的时候插入null
        memberPOMapper.insertSelective(memberPO);
    }
}
